/**
 * NSGAII_Settings2.java
 *
 * @author Antonio J. Nebro
 * @version 1.0
 *
 * NSGAII_Settings2 class of algorithm NSGAII
 */
package ufpr.mestrado.ais.experiments.settings;

import jmetal.base.Algorithm;
import jmetal.base.Problem;
import jmetal.base.operator.crossover.Crossover;
import jmetal.base.operator.mutation.Mutation;
import jmetal.base.operator.mutation.MutationFactory;
import jmetal.base.operator.selection.Selection;
import jmetal.experiments.Settings;
import jmetal.qualityIndicator.QualityIndicator;
import jmetal.util.JMException;
import ufpr.mestrado.ais.base.operator.crossover.SBXCrossoverMNO;
import ufpr.mestrado.ais.base.operator.selection.BinaryTournament2MNO;
import ufpr.mestrado.ais.metaheuristics.nsga2mno.NSGAIIMNO;
import ufpr.mestrado.ais.util.DominanceComparatorMNO;

/**
 * @author Antonio J. Nebro
 */
public class NSGAIIMNOSato_Settings extends Settings {
	public int populationSize_ = 200;
	public int maxEvaluations_ = 300;
	public double mutationProbability_ = 1.0 / problem_.getNumberOfVariables();
	public double crossoverProbability_ = 0.9;
	public double mutationDistributionIndex_ = 20.0;
	public double crossoverDistributionIndex_ = 20.0;

	/**
	 * Constructor
	 * 
	 * @throws JMException
	 */
	public NSGAIIMNOSato_Settings(Problem problem) throws JMException {
		super(problem);
	} // NSGAII_Settings2

	/**
	 * Configure NSGAII with user-defined parameter settings
	 * 
	 * @return A NSGAII algorithm object
	 * @throws jmetal.util.JMException
	 */
	public Algorithm configure() throws JMException {
		Algorithm algorithm;
		Selection selection;
		Crossover crossover;
		Mutation mutation;

		QualityIndicator indicators;

		// Creating the algorithm. There are two choices: NSGAII and its steady-
		// state variant ssNSGAII
		algorithm = new NSGAIIMNO(problem_);
		// algorithm = new ssNSGAII(problem_) ;

		// Algorithm parameters
		algorithm.setInputParameter("populationSize", populationSize_);
		algorithm.setInputParameter("maxEvaluations", maxEvaluations_);

		// Mutation and Crossover for Real codification
		crossover = new SBXCrossoverMNO();
		crossover.setParameter("probability", crossoverProbability_);
		crossover
				.setParameter("distributionIndex", crossoverDistributionIndex_);

		mutation = MutationFactory.getMutationOperator("PolynomialMutation");
		mutation.setParameter("probability", mutationProbability_);
		mutation.setParameter("distributionIndex", crossoverDistributionIndex_);

		// Selection Operator
		selection = new BinaryTournament2MNO(new DominanceComparatorMNO());

		// Add the operators to the algorithm
		algorithm.addOperator("crossover", crossover);
		algorithm.addOperator("mutation", mutation);
		algorithm.addOperator("selection", selection);

		// Creating the indicator object
		if ((paretoFrontFile_ != null) && (!paretoFrontFile_.equals(""))) {
			indicators = new QualityIndicator(problem_, paretoFrontFile_);
			algorithm.setInputParameter("indicators", indicators);
		} // if

		return algorithm;
	} // configure
} // NSGAII_Settings2
